package com.jqb.springlab.service.impl;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import com.jqb.springlab.service.PersonService;
/**
 * 测试bean完整的生命周期 13步-叼
 * @author Dong
 */
public class PersonServiceImpl implements PersonService, BeanNameAware,
		BeanFactoryAware, ApplicationContextAware, InitializingBean,
		DisposableBean {
	private String name;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
		System.out.println("setName...");
	}
	/*构造方法*/
	public PersonServiceImpl() {
		System.out.println("constructor invoked...");
	}
	public void showName() {
		System.out.println("showName:" + name);
	}
	/**
	 * 设置ID
	 */
	@Override
	public void setBeanName(String arg0) {
		// arg0这个其实就是配置文件中bean的id
		System.out.println("BeanNameAware->setBeanName:" + arg0);
	}
	/**
	 * 设置setBeanFactory
	 */
	@Override
	public void setBeanFactory(BeanFactory arg0) throws BeansException {
		// 传递BeanFactory(包含了所有bean)
		System.out.println("BeanFactoryAware->setBeanFactory:" + arg0);
	}
	/**
	 * 设置上下文
	 */
	@Override
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		System.out.println("ApplicationContextAware->setApplicationContext:"
				+ arg0);
	}
	/**
	 * processor的befor和after之间调用
	 */
	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("InitializingBean->afterPropertiesSet...");
	}
	/**
	 * 手动配置了init(在bean.xml中配置 )
	 */
	// 也可以用注解哦
	// @PostConstruct
	public void init() {
		System.out.println("init...");
	}
	/**
	 * 容器关闭后触发
	 */
	@Override
	public void destroy() throws Exception {
		System.out.println("DisposableBean->destroy container closed...");
	}
	/**
	 * 自定义销毁方法(在bean.xml中配置 )
	 */
	// 也可以用注解哦
	// @PreDestroy
	public void destroyBean() {
		System.out.println("destroyBean...");
	}
}
